/// \file
#ifndef FILE_globals_H
#define FILE_globals_H


//**
// Types definition.
//**
// This may cause small problems with vc, as until recently, it had no
// stdint.
#include "stdint.h"

#define FS_VERSION 1;

typedef uint8_t byte_t;

typedef uint8_t flags8_t;

#ifndef __cplusplus
	/// A boolean type for C.
	/// \note I know, this is not perfect. But it will hold unless someone
	/// test (x==true) or (x!=true).
	/// But because this is nonsense, That should hold.
	typedef enum{
		false = 0,
		true = 1
	} bool;
#endif


//**
// Standard functions returns.
//**
// Can't do an enum because FALSE and NO_PROBLEM
// Have the same value
#define ERR_OUT_OF_RESSOURCE -2
#define ERR_OUT_OF_MEMORY -1
#define ERR_OUT_OF_RANGE 2
#define ERR_CANT_DO_IT_ALWAYS 3
#define ERR_CANT_DO_IT_NOW 4
#define ERR_ALREADY_DONE 5
#define ERR_ALREADY_USED 6
#define ERR_NOT_FOUND 7
#define ERR_PATH_MALFORMATED 8
#define ERR_FORBIDDEN 9
#define ERR_PARAMETER_PROBLEM 10
#define ERR_EXTERNAL_LIB_PROBLEM 11
#define ERR_CANT_HAPPEN 100
#define RET_NO_PROBLEM 0
#define RET_TRUE 1
#define RET_FALSE 0
/// The return type used in all the core functions of the filesystem.
typedef int8_t fs_ret_t;


//**
// Display macros.
//**
#include <stdio.h>
#ifdef __DEBUG__
	/// Set it to false to temporary disable debug printing.
	bool GLOBAL_debugPrintEnabled;
	/// Same as printf, but can be muted on release.
	#define DEBUG_PRINT(...) {if(GLOBAL_debugPrintEnabled) printf(__VA_ARGS__);}
	/// Same as printing to error stream, but can be muted on release.
	#define WARNING_PRINT(...) {fprintf(stderr,__VA_ARGS__);}
	/// Placed in code segments that are not yet implemented.
	#define NOT_IMPLEMENTED {fprintf(stderr,"Not implemented (file \"%s\",%d).",__FILE__,__LINE__);exit(-1);}
	#define STATIC_DEBUG
#else // #ndef __DEBUG__
	#define DEBUG_PRINT(...) {}
	#define WARNING_PRINT(...) {}
	#define NOT_IMPLEMENTED {fprintf(stderr,"Not implemented.");}
	#define STATIC_DEBUG static
#endif // #end __DEBUG__


//**
// Error handling functions.
//**
// Understand : crash "cleanly".

/// Call this if a problem from which the file system can't recover happens.
/// Only in last recourse, and after printing the error details.
/// In theory, this should only be present in smoke tests,
/// or in case of huge corruption or totally irrationnal
/// or incompatible returns from called functions.
void fs_FATAL_LOGICAL_ERROR(void);

#endif // FILE_globals_H

